package singleUseDeprecated;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.Date;

public class SetDateFormatExample {
    private Date date;

    public SetDateFormatExample(Date date) {
        this.date = date;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public static String serializeDate(SetDateFormatExample example, int dateFormat) {
        Gson gson = new GsonBuilder().setDateFormat(dateFormat).create();
        return gson.toJson(example);
    }
    public static SetDateFormatExample deserializeDate(String json, int dateFormat) {
        Gson gson = new GsonBuilder().setDateFormat(dateFormat).create();
        return gson.fromJson(json, SetDateFormatExample.class);
    }

    //替换弃用API
    public static SetDateFormatExample deserializeDate2(String json, int dateStyle, int timeStyle) {
        // 使用 setDateFormat(int dateStyle, int timeStyle) 设置日期和时间格式
        Gson gson = new GsonBuilder().setDateFormat(dateStyle, timeStyle).create();
        return gson.fromJson(json, SetDateFormatExample.class);
    }
    public static String serializeDate2(SetDateFormatExample example, int dateStyle, int timeStyle) {
        Gson gson = new GsonBuilder().setDateFormat(dateStyle, timeStyle).create();
        return gson.toJson(example);
    }


}
